
package com.huizhan.web.dao;

import org.springframework.data.domain.*;
import org.springframework.data.jpa.repository.*;
import org.springframework.stereotype.Repository;
import java.util.*;
import com.huizhan.web.model.*;


@Repository 
public interface AccountLogDao extends JpaRepository<AccountLog,Long>
{
    /**
     * 根据项目id获取通行日志集合
     * @param projectId 项目ID
     * @return 日志集合
     */
    List<AccountLog> findByProjectId(String projectId);
    
    /**
     * 分页查询用户日志集合
     * @param name 姓名
     * @param remark 备注
     * @param type 类型
     * @param projectId 项目id
     * @param pageable 分页参数
     * @return 用户日志集合
     */
    @Query(
        value = "SELECT * FROM account_log"
            + " WHERE (type =?3 OR ?3 = 0 )"
            + " AND (project_Id =?4 OR ?4  = '' )"
            + " AND (name LIKE CONCAT('%',?1,'%') OR ?1  = '')"
            + " AND remark LIKE CONCAT('%',?2,'%') OR ?2  = '' ", 
        countQuery = "SELECT COUNT(1) FROM account_log"
            + " WHERE (type =?3 OR ?3 = 0 )"
            + " AND (project_Id =?4 OR ?4   = '' )"
            + " AND (name LIKE CONCAT('%',?1,'%') OR ?1  = '' )"
            + " AND (remark LIKE CONCAT('%',?2,'%') OR ?2  = '' )",
        nativeQuery = true
    )
    Page<AccountLog> findByWhere(String name,String remark,Long type,String projectId, Pageable pageable);
}
